package stud.aistar.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import stud.aistar.entity.*;
import stud.aistar.service.*;
import stud.aistar.vo.CommentUserVo;

import java.util.List;

/**
 * Created by Jcdz on 2019/10/6.
 */
@Controller
public class DocDetailController {

    @Autowired
    private IDoctorService doctorService;

    @Autowired
    private ISecondDepartmentService secondDepartmentService;

    @Autowired
    private ITimeService timeService;

    @Autowired
    private IWorkTimeService workTimeService;

    @Autowired
    private IDoctorTypeService doctorTypeService;

    @Autowired
    private ICommentUserVoService commentUserVoService;

    @GetMapping("/docdetail")
    public String docDetail(Model model, String docId, String sdeptId,
                            @RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "2")Integer pageSize){

        Doctor doctor = doctorService.findById(Integer.valueOf(docId));

        SecondDepartment sdepartment = secondDepartmentService.findById(Integer.valueOf(sdeptId));

        DoctorType doctorType = doctorTypeService.findBydocId(Integer.valueOf(docId));

        List<Time> timeList = timeService.findAll();

        PageInfo<CommentUserVo> pageInfo = commentUserVoService.findAll(pageNum,pageSize,Integer.valueOf(docId));

        List<WorkTime> workTimes = workTimeService.findByDocId(Integer.valueOf(docId));
        model.addAttribute("workTimes",workTimes);
        model.addAttribute("doctor",doctor);
        model.addAttribute("sdepartment",sdepartment);
        model.addAttribute("doctorType",doctorType);
        model.addAttribute("timeList",timeList);
        model.addAttribute("pageInfo",pageInfo);
        return "showmessage/docdetail";
    }
}
